package com.it.commicity.service.impl.zy;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.it.commicity.common.Result;
import com.it.commicity.domain.po.ZyUnit;
import com.it.commicity.domain.requestPass.Unit;
import com.it.commicity.domain.vo.RoomVo;
import com.it.commicity.domain.vo.UnitVo;
import com.it.commicity.mapper.zy.ZyUnitMapper;
import com.it.commicity.service.zy.IZyUnitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 单元  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-11
 */
@Service
public class ZyUnitServiceImpl extends ServiceImpl<ZyUnitMapper, ZyUnit> implements IZyUnitService {
    @Autowired
    private ZyUnitMapper unitMapper;

    @Override
    public Result selectUnitList(Unit unit) {
        Page<UnitVo> page = new Page<>(unit.getNowPage(), unit.getPageSize());
        Page<UnitVo> unitPage = unitMapper.getUnitPage(page, unit);
        if (unitPage.getRecords().size() <= 0) {
            return Result.fail("暂时没有数据");
        }
        return Result.success("查询成功", unitPage);
    }

    @Override
    public List<UnitVo> getExportData(ArrayList<Long> unitIds, Long communityId) {
        List<UnitVo> zyUnits = null;
        if (unitIds.size() <= 0) {
            zyUnits = unitMapper.selectListByCommunityId(communityId);
        } else {
            zyUnits = unitMapper.selectListByListRoomId(unitIds);
        }
        return zyUnits;
    }
}
